﻿<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="util.JdbcUtil" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="bean.WarehouseBean" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="bean.GoodsBean" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
  <head>
    <title>inventory</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link href="resources/css/axure_rp_page.css" type="text/css" rel="stylesheet"/>
    <link href="data/styles.css" type="text/css" rel="stylesheet"/>
    <link href="files/inventory/styles.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="layui/css/laytable.css">
    <script src="resources/scripts/jquery-3.2.1.min.js"></script>
    <script src="resources/scripts/axure/axQuery.js"></script>
    <script src="resources/scripts/axure/globals.js"></script>
    <script src="resources/scripts/axutils.js"></script>
    <script src="resources/scripts/axure/annotation.js"></script>
    <script src="resources/scripts/axure/axQuery.std.js"></script>
    <script src="resources/scripts/axure/doc.js"></script>
    <script src="resources/scripts/messagecenter.js"></script>
    <script src="resources/scripts/axure/events.js"></script>
    <script src="resources/scripts/axure/recording.js"></script>
    <script src="resources/scripts/axure/action.js"></script>
    <script src="resources/scripts/axure/expr.js"></script>
    <script src="resources/scripts/axure/geometry.js"></script>
    <script src="resources/scripts/axure/flyout.js"></script>
    <script src="resources/scripts/axure/model.js"></script>
    <script src="resources/scripts/axure/repeater.js"></script>
    <script src="resources/scripts/axure/sto.js"></script>
    <script src="resources/scripts/axure/utils.temp.js"></script>
    <script src="resources/scripts/axure/variables.js"></script>
    <script src="resources/scripts/axure/drag.js"></script>
    <script src="resources/scripts/axure/move.js"></script>
    <script src="resources/scripts/axure/visibility.js"></script>
    <script src="resources/scripts/axure/style.js"></script>
    <script src="resources/scripts/axure/adaptive.js"></script>
    <script src="resources/scripts/axure/tree.js"></script>
    <script src="resources/scripts/axure/init.temp.js"></script>
    <script src="resources/scripts/axure/legacy.js"></script>
    <script src="resources/scripts/axure/viewer.js"></script>
    <script src="resources/scripts/axure/math.js"></script>
    <script src="resources/scripts/axure/jquery.nicescroll.min.js"></script>
    <script src="data/document.js"></script>
    <script src="files/inventory/data.js"></script>
    <script type="text/javascript">
      $axure.utils.getTransparentGifPath = function() { return 'resources/images/transparent.gif'; };
      $axure.utils.getOtherPath = function() { return 'resources/Other.html'; };
      $axure.utils.getReloadPath = function() { return 'resources/reload.html'; };
    </script>
    </script>
    <script src="${pageContext.request.contextPath }/js/jquery.js"></script>
    <script >
      function add(iid){
        location.href="inventoryadd.jsp";
      }

      function modify(iid){
        var falg= confirm("确认修改吗？？？");
        if(falg){
          location.href="inventorymodify?iid="+iid;
        }
      }
      function del(iid){
        var falg= confirm("确认删除吗？？？");
        if(falg){
          location.href="inventorydelete?iid="+iid;
        }
      }
      function hunt(){
        var iid = $("#iid").val();
        var wname = $("#wname").val();
        if (iid==null &&wname==null){
          location.href="inventory.jsp";
        }
        $.ajax({
          url : "inventoryhunt?iid="+iid+"&wname="+wname,//提交地址
          type : "post",//提交方式（get,post）
          dataType : "json",//指定服务器返回的数据类型
          success : function(data) {//请求成功后的回调函数
            console.log(data);
            $("#tbody").empty(); //删除匹配的元素集合中所有的子节点（就是不重复执行）
            var trStr = "";
            for (var i = 0; i < data.length; i++) {
              trStr += "<tr><td>" + data[i].iid +
                      "</td><td>" + data[i].type +
                      "</td><td>" + data[i].wid +
                      "</td><td>" + data[i].wname +
                      "</td><td>" + data[i].number +
                      "</td><td>" + data[i].staff +
                      "</td><td>" + " <input type='button' value='删除' onclick='del(${gb.iid})' />"
                      +"<input type='button' value='修改' onclick='modify(${gb.iid})' />"+
                      "</td></tr>"
            }
            $("#tbody").show().append(trStr);//向<tbody>内部追加内容
          },
          error : function() {
            alert('请求失败');
          }
        });
      }
    </script>
    <style>
      .dadbox{
        position: relative;
      }
      .addbtn{
        position: absolute;
        top: 80px;
        left: 50px;
      }
      .table_huowu{
        /*
        width: 80%;
        //height: 500px;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;*/
        position: absolute;
        top: 120px;
        left: 50px;
      }
      .table_huowu table{
        border-collapse:collapse;
        width: 800px;
      }
      #u274_div{
        display: flex;
        justify-content: space-evenly;
        align-items: center;
        padding-top: 40px;
      }
      #iid,#wname{
        width:200px;
        height: 30px;
      }
      #sub{
        text-align: center;
        width: 70px;
        height: 30px;
        background-color:rgb(130,212,248) ;
        border: 0 solid #ffffff;
      }
      #sut{
        background-color:rgb(130,212,248) ;
        width: 80px;
        height: 30px;
        text-align: center;
        color: #ffffff;
        border: 0 solid #ffffff;
        border-radius:3px;
      }
      td{
        white-space: nowrap;
      }
    </style>
    <%
      String sql="SELECT * FROM inventory";
      try {
        PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        ArrayList<GoodsBean> arr=new ArrayList<GoodsBean>();
        while (rs.next()){
          GoodsBean gb=new GoodsBean();
          gb.setIid(rs.getInt(1));
          gb.setType(rs.getString(2));
          gb.setWid(rs.getInt(3));
          gb.setWname(rs.getString(4));
          gb.setNumber(rs.getInt(5));
          gb.setStaff(rs.getString(6));
          arr.add(gb);
        }
        request.setAttribute("arr",arr);

      } catch (Exception e) {
        e.printStackTrace();
      }
    %>
  </head>
  <body>
    <div id="base" class="">

      <!-- Unnamed (矩形) -->
      <div id="u272" class="ax_default box_1">
        <div id="u272_div" class="dadbox">
          <%--按钮--%>
          <div class="addbtn">
            <input type="submit" value="添加" id="sut" onclick="add(${gb.iid})" />
          </div>
          <%--表格--%>
          <div class="table_huowu">
            <table class="layui-table">
              <thead>
              <tr>
                <th>货物id</th>
                <th>类型</th>
                <th>仓库id</th>
                <th>仓库名称</th>
                <th>库存数量</th>
                <th>入库员</th>
                <th>操作</th>
              </tr>
              </thead>
              <tbody id="tbody">
              <c:forEach items="${arr}" var="gb">
                <tr>
                  <td>${gb.iid}</td>
                  <td>${gb.type}</td>
                  <td>${gb.wid}</td>
                  <td>${gb.wname}</td>
                  <td>${gb.number}</td>
                  <td>${gb.staff}</td>
                  <td><input type='button' value='删除' onclick='del(${gb.iid})' />
                    <input type='button' value='修改' onclick='modify(${gb.iid})' />
                  </td>
                </tr>
              </c:forEach>
              </tbody>
            </table>
          </div>
        </div>
        <div id="u272_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u273" class="ax_default _文本段落">
        <div id="u273_div" class=""></div>
        <div id="u273_text" class="text ">
          <p><span>库存信息管理</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u274" class="ax_default box_1">
        <div id="u274_div" class="">
          <input id="iid" placeholder="货物ID" type="text"/>
          <input type="text" id="wname" placeholder="仓库名称"/>
          <input type="submit"id="sub" value="筛选" onclick="hunt()">
        </div>
        <div id="u274_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u277" class="ax_default label">
        <div id="u277_div" class=""></div>
        <div id="u277_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u286" class="ax_default box_1">
        <div id="u286_div" class=""></div>
        <div id="u286_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (图片 ) -->
      <div id="u287" class="ax_default _图片_">
        <img id="u287_img" class="img " src="images/customer/u149.png"/>
        <div id="u287_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u288" class="ax_default label">
        <div id="u288_div" class=""></div>
        <div id="u288_text" class="text ">
          <p><span>筛选</span></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u289" class="ax_default box_1">
        <div id="u289_div" class=""></div>
        <div id="u289_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (SVG) -->
      <div id="u290" class="ax_default _图片_">
        <img id="u290_img" class="img " src="images/customer/u152.svg"/>
        <div id="u290_text" class="text " style="display:none; visibility: hidden">
          <p></p>
        </div>
      </div>

      <!-- Unnamed (矩形) -->
      <div id="u291" class="ax_default label">
        <div id="u291_div" class=""></div>
        <div id="u291_text" class="text ">
          <p><span>列表</span></p>
        </div>
      </div>

    </div>
    <script src="resources/scripts/axure/ios.js"></script>
  </body>
</html>
